package outline;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.net.URL;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JToolBar;
import javax.swing.JMenuBar;
import javax.swing.JButton;


//툴바 toolbar
//작성순서 : toolbar 작성 -> 버튼 생성 -> 툴바에 추가
public class J08_HelloSwingToolbar extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					J08_HelloSwingToolbar frame = new J08_HelloSwingToolbar();
					frame.setLocationRelativeTo(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public J08_HelloSwingToolbar() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JToolBar toolBar = new JToolBar(); //툴바생성
		toolBar.setFloatable(false);	//툴바 이동방지
		//toolBar.setFocusable(false);	//클릭시 테두리제거???
		
		//툴바 클릭시 이벤트 처리를 담당할 클래스 등록
		J07_HelloSwingActionListener action = new J07_HelloSwingActionListener();
		
		contentPane.add(toolBar, BorderLayout.NORTH);
		
		JButton btnNewButton = new JButton();
		toolBar.add(btnNewButton);
		btnNewButton.setFocusPainted(false);//클릭시 테두리 제거
		btnNewButton.addActionListener(action);//이벤트 처리
		btnNewButton.setActionCommand("new");//명령등록
		
		//URL iconURL = getClass().getResource("/images/main/new.png");
		//btnNewButton.setIcon(new ImageIcon(iconURL));
		//URL을 메서드로 생성
		//툴바 버튼에 이미지 지정
		btnNewButton.setIcon(new ImageIcon(this.getURL("new")));
		//툴바 버튼에 툴립(용도설명) 추가
		btnNewButton.setToolTipText("새로만들기");
		toolBar.add(btnNewButton);//툴바에 추가
		
		JButton btnNewButton_1 = new JButton();
		btnNewButton_1.setFocusPainted(false);//클릭시 테두리 제거
		btnNewButton_1.addActionListener(action);//이벤트 처리
		btnNewButton_1.setActionCommand("close");//명령등록
		
		//URL iconURL2 = getClass().getResource("/images/main/close.png");
		btnNewButton_1.setIcon(new ImageIcon(this.getURL("close")));
		btnNewButton_1.setToolTipText("닫기");
		
		toolBar.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton();
		btnNewButton_2.setFocusPainted(false);//클릭시 테두리 제거
		btnNewButton_2.addActionListener(action);//이벤트 처리
		btnNewButton_2.setActionCommand("exit");//명령등록
		
		//URL iconURL3 = getClass().getResource("/images/main/exit.png");
		//btnNewButton_2.setIcon(new ImageIcon(iconURL3));
		btnNewButton_2.setIcon(new ImageIcon(this.getURL("exit")));
		btnNewButton_2.setToolTipText("종료");
		
		toolBar.add(btnNewButton_2);
	}
	
	//url을 메서드로 생성
	private URL getURL(String img){
		
		URL iconURL = getClass().getResource("/images/main/"+img+".png");
		
		return iconURL;
	}
}
